export default function (list) {
  if (list.length <= 0) return [];
  let arr = list.filter((item) => item.parentId == null);
  let childArr = list.filter((item) => item.parentId != null);

  console.log(arr, "主");
  console.log(childArr, "从");
  for (let i = 0; i < arr.length; i++) {
    for (let j = 0; j < childArr.length; j++) {
      if (childArr[j].parentId === arr[i].id) {
        if (!arr[i].children) {
          arr[i].children = [];
          arr[i].children.push(childArr[j]);
        } else {
          arr[i].children.push(childArr[j]);
        }
      }
    }
  }
  return arr;
}
